package com.pinxi.controller;

import com.pinxi.VO.SysResult;
import com.pinxi.pojo.User;
import com.pinxi.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author shaohe_zhang
 * @Date 2022/1/24 15:07
 * @Version 1.0.0
 */
@RestController
@CrossOrigin
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/getAll")
    public SysResult getAll(){
        return SysResult.success(userService.getAll());
    }

    @PostMapping("/login")
    public SysResult login(@RequestBody User user){
        String token = userService.login(user);
        if (token == null || token == "")
            return SysResult.fail();
        return SysResult.success(token);
    }
}
